import { getYMD, getNowFormatDate, compareObject } from '../../../../assets/js/util.js'
export default {
    data() {
        return {
            title: 'Auany统计概况',
            xlsxTitle:'',
            // 默认参数 和 URL
            SRC: '',
            DP: {
                p: '',
                f: ''
            },
            
            nowDate: getNowFormatDate(),
            date: getYMD(0),
            loading: false,
            searchable: false,
            pickerOptions: {
                disabledDate(time) {
                    if (time.getTime() < Date.now() - (8.64e7 * 7) || time.getTime() > Date.now()) {
                        return time.getTime();
                    }
                }
            },
            dialogFormVisible: false,
            formLabelWidth: '100px',
            tabelDatas: [],
            /*realTimeServiceContent 的宽*/
            realTimeServiceContent: '100%',
            /*表的宽度*/
            realTimeServiceTableWidth: "100%",
            /*数据表头*/
            tabelHead: [
                { prop: "channelid", label: "渠道" },
                { prop: "newUser", label: "新增" },
                { prop: "activeUser", label: "活跃" },
                { prop: "payUser", label: "付费帐号" },
                { prop: "pay", label: "付费金额("+localStorage.getItem("ZULONGBICURRENCY")+")" }
            ],
            /*分页器*/
            currentPage: 1
        }
    },
    computed: {
        // xlsx() {
        //     return this.title + '.xlsx'
        // }
    },
    methods: {
        successFun(data) {
            this.$message({
                message: data,
                type: 'success'
            });
        },
        errorFun(data) {
            this.$message.error(data);
        },
        dateChange(val) {
            this.date = val
        },
        loads() {
            this.loading = !this.loading; //加载中
            this.searchable = !this.searchable; //查询按钮不可用
        },
        //查询按钮
        search(form) {
            if (this.date == undefined || this.date.length < 0) {
                this.errorFun('请完善输入的值！');
                this.date = getNowFormatDate()
                return false;
            } else {
                this.getData()
            }
        },
        // 表格下载
        excel(tableIndex,sheet) {
            var that = this;
            that.xlsxTitle = sheet+"-"+that.date;
            that.downloadExl(that.tabelHead, that.tabelDatas,that.xlsxTitle, that.title);
        },
        /*获取数据*/
        getData() {
            this.loads();
            /*`${this.SRC}auanyDisplayByChannelBiAction/search.do?date=${this.date}`*/
            this.$http.jsonp(`${this.SRC}data/get.do?p=${this.DP.p}&f=${this.DP.f}&a=search`, {
                params: { 'ps': `date=${this.date}` }
            }).then(function(res) {
                var data = JSON.parse(JSON.parse(res.body));
                this.loads()
                if (parseInt(data['res']) === 0) {
                    this.nowDate = getNowFormatDate()
                    if (data.data.length == 0) {
                        this.tabelDatas = [];
                        this.errorFun("暂无数据！")
                    } else {
                        var datas = data.data;
                        this.tabelDatas = [];
                        this.tabelDatas = datas;
                    }
                } else {
                    this.getErrorMsg(Number(data.res))
                }
            })
        },
        /*设置初始值*/
        _init() {
            window.addEventListener('resize', function() {
                /*修改表格的宽度*/
                this.realTimeServiceTableWidth = document.body.clientWidth - 240 + "px";
                this.realTimeServiceContent = document.body.clientWidth - 220 + "px";
            }.bind(this))
        },
        // 表格排序
        sortChange(column) {
            if (column.prop === null) {
                return;
            } else if (column.order === 'descending') {
                this.tabelDatas.sort(compareObject(column.prop, false));
            } else { //正序
                this.tabelDatas.sort(compareObject(column.prop, true));
            }
           // this.tableControl();
        }
    },
    mounted() {
        this._init()
            // 初始化URL
        this.SRC = this.$store.getters.src;
        this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
        this.DP.f = localStorage.getItem('ZULONGBIPAGEID');
        this.getData()
    }
}